var line = {
		index:0,
		code:'',
		name:'',	
		price:0,
		validation:'',
		tradeType:'',
		contractType:'',
		remark:'',
		storage:0,
		list:[
		      /**
		      {
		    	  month:1,
		    	  assumpsit:0,
		    	  custome:0,
		    	 
		      }
		      */
		      
		      ]
		
};
$(function(){
	setAutoComplete("#code");	
});
function addItem(){    
	var parent = window.dialogArguments;
	alert($.param(line));
   	parent.addLine(line);
	$("#cform").get(0).reset();
}

function onIndexedPropertyChange(index,pname,self){
	line.list[imx][pname] = $(self).val();
}


function onListPropertyChange(pname,self){
	var clt = $("option:selected",self); 
	line[pname] = clt.val();
}

function onValuePropertyChange(pname,self){
	line[pname] = $(self).val();	
}

function onTextPropertyChange(pname,self){
	line[pname] = $(self).text();
}

function setAutoComplete(objId) {
    var obj = $(objId);
	obj.autocomplete({
		minLength : 3,
		source : function(request, response) {
			var term = request.term;
			$.getJSON(
					"../product/product!searchall", 
					{"term" : term}, 
					function(data) {
						response(data);
					}							
			);
		},
		focus : function(event, ui) {
			obj.val(ui.item.code);
			return false;
		},
		select : function(event, ui) {
			obj.val(ui.item.code);	
			$("#name").text(ui.item.name);
			line.code = ui.item.code;
			line.name = ui.item.name;
			return false;
		}

	})
	.data("autocomplete")._renderItem = function(ul, item) {
		return $("<li></li>").data("item.autocomplete", item).append(
				"<a>" + item.code + "|" + item.name + "</a>").appendTo(ul);
	};
}